<template>
	<view>
		 <!-- 导航栏 -->
		  <uni-nav-bar left-icon="left"  :statusBar="true" titleSize="30px" leftText="返回"  right-text="修改"  title="工程部详情"  @clickLeft="back" @clickRight="editfn"   :fixed="true" backgroundColor="#3286ed" color="#fff"/>
	
	<!-- 列表 -->
		<view v-if="Object.values(infomation).length > 0">
			<view class="box">
				<view style="color: #ffc849 ;">单号：{{infomation.serialNum}}</view>
				<view>订单编号：{{infomation.orderNo}}</view>
				<view>项目名称：{{infomation.projectName}}</view>
				<view>服务人员：{{infomation.userName}}</view>
			</view>
			<view style="background-color: #fff;margin: 5px 3px;padding: 8px;">
				<u-cell title="进度:"></u-cell>
				<u-steps :current="parseFloat(active)-1"   direction="row" style='margin-left: 10px;margin-top: 20px;' >
						<u-steps-item v-for="item in ApprovalList" :title="item.approverName" :desc="item.remark">
							<!-- <text class="slot-icon" slot="icon">{{item.approverName.substr(0,1)}}</text> -->
						</u-steps-item>
				</u-steps>
				
			</view>
			
			<view style="background-color: #fff;margin-top: 5px;">
				<u-cell>
					<template #title>
						<view style="font-size: 12px;">基本信息</view>
					</template>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">单号</text>
						<text class="u-cell-text">{{infomation.serialNum}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">发起人</text>
						<text class="u-cell-text">{{infomation.applicantName}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">订单编号</text>
						<text class="u-cell-text">{{infomation.orderNo}}</text>
					</view>
				</u-cell>
				
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">项目名称</text>
						<text class="u-cell-text">{{infomation.projectName}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">业务员</text>
						<text class="u-cell-text">{{infomation.salesmanName}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">项目地址</text>
						<text class="u-cell-text">{{infomation.projectAddress}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">服务类别</text>
						<text style="color: #ffc849;" v-if="infomation.serviceType=='0'" class="u-cell-text">安装调试</text>
						<text style="color: #ffc849;" v-if="infomation.serviceType=='1'" class="u-cell-text">设备维修</text>
						<text style="color: #ffc849;" v-if="infomation.serviceType=='2'" class="u-cell-text">驻场维修</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">服务人员</text>
						<text class="u-cell-text">{{infomation.userName}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">出差天数</text>
						<text class="u-cell-text">{{infomation.days}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">费用合计</text>
						<text class="u-cell-text">{{infomation.costs}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">情况说明</text>
						<text class="u-cell-text">{{infomation.salesmanRemark}}</text>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">现场照片</text>
						<a :href="`http://101.132.141.5:8081${infomation.userPhoto}`">
							<u--image :showLoading="true" :src="`http://101.132.141.5:8081${infomation.userPhoto}`"  width="80px" height="80px" ></u--image>
						</a>
					</view>
				</u-cell>
				<u-cell>
					<view  slot="title" class="u-slot-title">
						<text class="u-cell-text">服务结果说明</text>
						<text class="u-cell-text">{{infomation.engineerRemark}}</text>
					</view>
				</u-cell>
			</view>
		</view>
		<view v-if="Object.values(infomation).length == 0" class="BGC"></view>
	<u-toast ref="uToast"></u-toast>
	</view>
	</view>
</template>

<script>
	import{getCost,listCost} from '@/api/enginee.js'
	import {getapprovalRecodeList,editapprovalRecode} from '@/api/approvaRecode.js'
	export default {
		data(){
			return{
				infomation:{},
				ApprovalList:[],//审批
				active:0,
				buttonShow:false,
				showAgree:false,
				approvalForm:{}
			}
		},
		onLoad(option){
			this.infomation = JSON.parse(decodeURIComponent(option.item))
			console.log(this.infomation);
			 
		},
		created() {
			this.getengin()
		},
		methods:{
			 editfn(){
			 
				  this.ApprovalList.forEach(item=>{
					  console.log(this.active,this.$store.getters.userid,item.approverId);
					  
					 if(this.$store.getters.userid==item.approverId){
						if(item.sequence==2 || item.sequence==3){
											 uni.redirectTo({
											 	url:"/pages/ebgineeCost/addenginee/addenginee?id="+this.infomation.id
											 })
						}else{
						 editapprovalRecode({serialNum:this.infomation.serialNum,typeOperation:'agree'}) 
						} 
					 }
				  })
				
			 },
			
			async getengin(){
				console.log(this.infomation);
				if(this.infomation.approvalStatus){
					let res=await listCost({serialNum:this.infomation.serialNum})
					this.infomation=res.rows[0]
					let res1= await getapprovalRecodeList({serialNum:this.infomation.serialNum})
					this.ApprovalList=res1.rows
					var arr=res1.rows
					for(var i=0;i<arr.length;i++){
					  for(var j=i+1;j<arr.length;j++){
					    //如果第一个比第二个大，就交换他们两个位置
					    if( arr[i].sequence>arr[j].sequence){
					      var temp = arr[i];
					      arr[i] = arr[j];
					      arr[j] = temp;
					    }
					  }
					}
					this.ApprovalList=arr
					 this.active=0
					  this.ApprovalList.forEach(item=>{
											if(item.approvalStatus==="completed"){
												this.active++
											}
										})
				}else{
					let res=await getCost(this.infomation.id)
					this.infomation=res.data
					let res1= await getapprovalRecodeList({serialNum:this.infomation.serialNum})
					this.ApprovalList=res1.rows
					var arr=res1.rows
					for(var i=0;i<arr.length;i++){
					  for(var j=i+1;j<arr.length;j++){
					    //如果第一个比第二个大，就交换他们两个位置
					    if( arr[i].sequence>arr[j].sequence){
					      var temp = arr[i];
					      arr[i] = arr[j];
					      arr[j] = temp;
					    }
					  }
					}
					this.ApprovalList=arr
					 this.active=0
					  this.ApprovalList.forEach(item=>{
											if(item.approvalStatus==="completed"){
												this.active++
											}
										})
				}
				
			},
			// editfn(){
			// 	uni.navigateTo({
			// 		url:"/pages/ebgineeCost/addenginee/addenginee?id="+this.infomation.id
			// 	})
			// },
			back(){
				uni.redirectTo({
					url:'/pages/ebgineeCost/ebgineeCost'
				})
			},
			
		}
	}
</script>

<style lang="scss">
	.u-slot-title{
		.u-cell-text{
			margin-right: 15px;
		}
	}
	.bgc{
		width: 10px;
		height: 10px;
		line-height: 10px;
		display: inline-block;
		text-align: center;
		background-color: #fd9540;
	}
	.box{
		padding: 10px;
		font-size: 14px;
		background-color: #fff;
	}
	.BGC{
		width: 100%;
		min-height: 400px;
		background-image: url('@/static/images/bgc.png');
		background-size:100% 200px;
		background-repeat: no-repeat;
	}
</style>